using System;

using Supremacy.Annotations;

namespace SupremacyEditor
{
    public sealed class EditorTypeAttribute : Attribute
    {
        public Type EditorType { get; private set; }

        public EditorTypeAttribute([NotNull] Type editorType)
        {
            if (editorType == null)
                throw new ArgumentNullException("editorType");
            this.EditorType = editorType;
        }

        public static Type GetEditorType([NotNull] Type itemType)
        {
            if (itemType == null)
                throw new ArgumentNullException("itemType");
            var editorTypeAttribute = GetCustomAttribute(itemType, typeof(EditorTypeAttribute)) as EditorTypeAttribute;
            if (editorTypeAttribute == null)
                return null;
            return editorTypeAttribute.EditorType;
        }
    }
}